import Vue from 'vue'
import VueRouter from 'vue-router'
import Movie from '@/views/movie'
import Playing from '@/views/movie/playing'
import Feature from '@/views/movie/feature'
import Moviedetail from '@/views/movie/detail'
import Cinema from '@/views/cinema'
import Cinemadetail from '@/views/cinema/detail'
import News from '@/views/news'
import My from '@/views/my'
import City from '@/views/city'
Vue.use(VueRouter)

// 处理路由跳转到当前页面报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err)
}

const routes = [
  {
    path: '/',
    redirect: '/movie/playing'
  },
  {
    path: '/login',
    component: () => import('@/views/login')
  },
  {
    path: '/movie',
    component: Movie,
    redirect: '/movie/playing',
    children: [
      {
        path: 'playing',
        component: Playing,
        meta: {
          keepAlive: true // false表示在该路由不予显示 //true表示在该路由显示
        }
      },
      {
        path: 'feature',
        component: Feature,
        meta: {
          keepAlive: true // false表示在该路由不予显示 //true表示在该路由显示
        }
      },
      {
        path: 'detail',
        component: Moviedetail,
        meta: {
          keepAlive: false // false表示在该路由不予显示 //true表示在该路由显示
        }
      }
    ]
  },
  {
    path: '/cinema',
    component: Cinema,
    meta: {
      keepAlive: true // false表示在该路由不予显示 //true表示在该路由显示
    },
    children: [
      {
        path: 'detail',
        component: Cinemadetail,
        meta: {
          keepAlive: false // false表示在该路由不予显示 //true表示在该路由显示
        }
      }
    ]
  },
  {
    path: '/news',
    component: News
  },
  {
    path: '/my',
    component: My,
    meta: {
      keepAlive: true // false表示在该路由不予显示 //true表示在该路由显示
    }
  },
  {
    path: '/city',
    component: City,
    meta: {
      keepAlive: false // false表示在该路由不予显示 //true表示在该路由显示
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
